import random
import uuid
from datetime import date

from fastapi import APIRouter

from service.attendance import PunchClockRequest, punch_clock

router = APIRouter()

lgts = [117.708773, 117.70878, 117.70879, 117.708774, 117.708775]
lats = [39.023775, 39.023784, 39.023781, 39.023782, 39.023783, 39.023805]


@router.get("/comeWork", summary="上班")
def come_work():
	return work(1)


@router.get("/goOffWork", summary="下班")
def go_off_work():
	return work(3)


def work(cardType: int):
	lgt = random.choice(lgts)
	lat = random.choice(lats)
	date_str = date.strftime(date.today(), "%Y%m%d")
	id_str = str(uuid.uuid1()).replace("-", "")
	face_url = f"https://rock-check.obs.cn-southwest-2.myhuaweicloud.com:443/{date_str}_{id_str}.png"
	request = PunchClockRequest(
		lgt=lgt,
		lat=lat,
		cardType=cardType,
		cardPlace="天津市天津市滨海新区第二大街msd-b1大堂(泰达MSD附近)",
		userFaceUrl=face_url,
	)
	return punch_clock(request=request)
